﻿Option Explicit On

Imports System.Text
Imports Global_Visas_Data_Layer.DataAccess
Imports Global_Visas_Business_Layer.GlobalCRM
Public Class TasksEvents

    Public Enum ViewTypes
        Consultant = 1
        Message = 2
    End Enum

    Public Enum EventTypes
        NotSet = 0
        EventCase = 1
        EventPerson = 2
        EventCompany = 3
        EventUserTask = 4
    End Enum

    Public Enum LinkTypes
        None = 0
        eCase = 1
        Person = 2
        Company = 3
        Consultant = 4
    End Enum

    Public Enum EventStatus
        SingleEvent = 1
        Task = 2
    End Enum

    Public Structure EventLinkInfo
        Public EventLinkId As Integer
        Public EventLinkTypeId As Integer
        Public EventGroupId As Integer
        Public EventLinkOrder As Integer
        Public EventLinkStageStart As Integer
        Public EventLinkStageEnd As Integer
    End Structure

    Public Structure EventInfo
        Public EventId As Long
        Public CategoryId As Integer
        Public Description As String
        Public Message As String
        Public DateEntered As Date
        Public DateScheduled As Date
        Public DateCompleted As Date
        Public LinkType As Integer
        Public LinkId As Long
        Public VIP As Integer
        Public KeyDate As Integer
        Public EnteredBy As String
        Public ScheduledFor As String
        Public CompletedBy As String
    End Structure

    'Public Function GetLastEventMessage(ByVal ViewType As ViewTypes, ByVal LinkId As Long) As String
    '    Try


    '        Dim SQL As New StringBuilder
    '        Dim Msg As New StringBuilder
    '        Dim myTab As DataTable

    '        Select Case ViewType

    '            Case ViewTypes.Consultant
    '                With SQL
    '                    .Append("Select con_name, Event_Description, Event_Message, Event_DTentered ")
    '                    .Append(" From D_Event Left Outer Join")
    '                    .Append(" L_Consultant on D_Event.Event_EnteredBy = L_Consultant.Con_ID")
    '                    .Append(" Where Event_LinkType = 1 ")
    '                    .Append(" AND Event_LinkID = " & LinkId)
    '                    .Append(" ORDER BY Event_ID Desc")
    '                End With
    '            Case ViewTypes.Message
    '                With SQL
    '                    .Append("Select Event_Message from D_Event ")
    '                    .Append(" Where Event_LinkType = 1 ")
    '                    .Append(" AND Event_LinkID = " & LinkId)
    '                    .Append(" AND ((Event_KeyType = 1) OR (Event_Description = 'Webform Data'))")
    '                    .Append(" ORDER BY Event_ID")
    '                End With
    '        End Select

    '        myTab = DB.GetSQLDataTable(SQL.ToString)

    '        If Not IsNothing(myTab) Then
    '            If myTab.Rows.Count > 0 Then

    '                Dim myRow As DataRow

    '                myRow = myTab.Rows(0)

    '                If ViewType = ViewTypes.Consultant Then
    '                    With Msg
    '                        .Append(myRow("con_name") & vbCrLf)
    '                        .Append(myRow("Event_DTEntered") & vbCrLf)
    '                        .Append(myRow("Event_Description") & vbCrLf & vbCrLf)
    '                        .Append(myRow("Event_Message"))
    '                    End With
    '                Else
    '                    Msg.Append(myRow("Event_Message"))
    '                End If
    '            Else
    '                Msg.Append("Not Found")
    '            End If
    '        Else
    '            Msg.Append("Not Found")
    '        End If

    '        Return Msg.ToString
    '    Catch ex As Exception

    '    End Try

    'End Function

    Public Function GblFunc_Add_Event(ByVal EventType As String, ByVal EventMessage As String, ByVal Event_Status As EventStatus, ByVal LinkID As Long, ByVal LinkType As EventTypes, Optional ByVal Event_Urgent As Integer = 0, Optional ByVal EventKeydate As Integer = 0, Optional ByVal Event_SchFor As Integer = 0, Optional ByVal Event_SchDT As Date = Nothing, Optional ByVal UserEvent As Integer = 0, Optional ByVal objDate As Object = Nothing) As Long
        Dim cmn As New CommonFuncs
        Dim dataaccess As New Global_Visas_Data_Layer.DataAccess
        Dim SQL As StringBuilder
        Dim identity As Long

        Try

            Dim myFields As String = String.Empty
            Dim myData As String = String.Empty

            If LinkID = 0 And LinkType <> EventTypes.EventUserTask Then
                MsgBox("System tried to create an event, but no link was specified!", MsgBoxStyle.Critical)
                Exit Function
            End If

            If LinkType = LinkTypes.None Then
                MsgBox("System tried to create an event, but no link type was specified!", MsgBoxStyle.Critical)
                Exit Function
            End If

            If Event_Status = 2 And (Event_SchFor = 0 Or IsDBNull(Event_SchDT)) Then
                MsgBox("System tried to create an event, but schedule details were not specified!", MsgBoxStyle.Critical)
                Exit Function
            End If

            If Event_Status = 2 Then
                myFields = ", Event_ScheduledFor, Event_DTScheduled, Event_VIP"
                myData = "," & Event_SchFor & ", '" & cmn.FormatDate(Event_SchDT, True) & "'," & Event_Urgent & ""
            End If

            '        CRM3_AddEvent 0,"test","Sumchu",269,2,757302,
            '1,0,0,0,269,
            '        getdate()


            'Return dataaccess.GetSQLScalar("CRM3_AddEvent 0,'" & cmn.SwapQuotes(EventType) & "','" & cmn.SwapQuotes(EventMessage) & "'," & GlobalCRM.CurrentConID & "," & Event_Status & "," & LinkID & "," & LinkType & "," & EventKeydate & "," & Event_Urgent & "," & UserEvent)
            Dim test As Singleton = Singleton.Instance
            Dim currentconid As String = test.CurrentConId
            If objDate = Nothing Then
                SQL = New StringBuilder
                With SQL
                    .Append("INSERT INTO D_Event ( Event_Description, Event_Message, Event_EnteredBy, Event_DTEntered, Event_Category, Event_LinkID, Event_LinkType, Event_Keydate" & myFields & ", Event_UserEvent)")
                    .Append(" VALUES ( '" & cmn.SwapQuotes(EventType) & "', '" & cmn.SwapQuotes(EventMessage) & "', " & currentconid & ", '" & cmn.FormatDate(Now, True) & "', " & Event_Status & ", " & LinkID & ", " & LinkType & " , " & EventKeydate & myData & "," & UserEvent & " )")
                End With
            Else
                SQL = New StringBuilder
                With SQL
                    .Append("INSERT INTO D_Event ( Event_Description, Event_Message, Event_EnteredBy, Event_DTEntered, Event_Category, Event_LinkID, Event_LinkType, Event_Keydate" & myFields & ", Event_UserEvent)")
                    .Append(" VALUES ( '" & cmn.SwapQuotes(EventType) & "', '" & cmn.SwapQuotes(EventMessage) & "', " & currentconid & ", '" & cmn.FormatDate(CDate(objDate), True) & "', " & Event_Status & ", " & LinkID & ", " & LinkType & " , " & EventKeydate & myData & "," & UserEvent & " )")
                End With
            End If

            identity = dataaccess.ExecuteSQL(SQL.ToString, True)
            If identity > 0 Then
                Return identity
            Else
                Return 0
            End If

        Catch ex As Exception
            Return 0
        Finally
            cmn = Nothing
            dataaccess = Nothing
            SQL = Nothing
        End Try

    End Function

    Public Function DismissTask(ByVal EventId As Long, ByVal ConId As Integer, ByVal CompletionNote As String, ByRef LinkId As Long, ByRef LinkType As EventTypes) As Boolean
        Dim Cmn As New CommonFuncs
        ' Dim SQL As New StringBuilder
        Dim myData As DataTable
        Dim dataAccess As New Global_Visas_Data_Layer.DataAccess
        Try


            'SQL.Append("Select Event_message, Event_LinkId, Event_LinkType from D_Event where Event_ID = " & EventId)

            myData = dataAccess.GetSQLDataTable("CRM3_GetEventFromID " & EventId)
            ' myData = DB.GetSQLDataTable(SQL.ToString)

            If Not IsNothing(myData) Then
                If myData.Rows.Count > 0 Then

                    Dim myRow As DataRow = myData.Rows(0)
                    Dim Msg As String = myRow.Item("event_message") & vbCrLf & "---------------------------------------------------------" & vbCrLf & "Completion message" & vbCrLf & vbCrLf & CompletionNote.Trim

                    LinkId = myRow.Item("Event_LinkID")
                    LinkType = myRow.Item("Event_Linktype")

                    ' SQL = New StringBuilder
                    Return CBool(dataAccess.ExecuteSQL("CRM3_CloseTask 0," & EventId & "," & ConId & "," & Cmn.SwapQuotes(Msg)))

                    'With SQL
                    '    .Append("UPDATE D_Event ")

                    '    .Append(" SET Event_Category = 3")
                    '    .Append(", Event_CompletedBy = '" & ConId & "'")
                    '    .Append(", Event_DTCompleted = '" & Cmn.FormatDate(Now, True) & "'")
                    '    .Append(", Event_message = '" & Cmn.SwapQuotes(Msg) & "'")
                    '    .Append(" WHERE Event_ID = " & EventId)
                    'End With

                    'Return dataAccess.ExecuteSQL(SQL.ToString)
                    dataAccess = Nothing
                End If
            End If
        Catch ex As Exception

        Finally
            Cmn = Nothing
            dataAccess = Nothing
        End Try
    End Function

    Public Function GetEventTypes() As DataTable
        Dim dataAccess As New Global_Visas_Data_Layer.DataAccess
        Try

            Dim SQL As New StringBuilder

            Return dataAccess.GetSQLDataTable("CRM3_GetEventTypes")
            'With SQL
            '    .Append("Select EventType_ID,EventType_Name,Case EventType_Scope When 1 then 'Sales' When 2 then 'Casework' else 'All' end as Scope,")
            '    .Append("Case EventType_CustomerType When 0 then 'All' when 1 then 'Private' when 2 then 'Corporate' end As CType")
            '    .Append(" FROM L_EventTypes Order By EventType_Name")
            'End With

            'Return DB.GetSQLDataTable(SQL.ToString)
        Catch ex As Exception
            Return Nothing
        Finally
            dataAccess = Nothing
        End Try

    End Function

    Public Function EventGroupList() As DataTable
        Dim dataAccess As New Global_Visas_Data_Layer.DataAccess
        Try

            Return dataAccess.GetSQLDataTable("CRM3_GetEventGroupList")

        Catch ex As Exception
            Return Nothing
        Finally
            dataAccess = Nothing
        End Try

    End Function

    Public Function EventsInGroup(ByVal EventGroupId As Integer) As DataTable
        Dim dataAccess As New Global_Visas_Data_Layer.DataAccess
        Dim sql As StringBuilder
        Try

            sql = New StringBuilder

            With sql
                .Append("SELECT I_EventLinks.EventLink_ID, L_EventTypes.EventType_Name,ISNULL(Sec_Access.SecAccess_Name, '') AS SecAccess,")
                .Append("CASE EventLink_StageStart when 0 then 'New Lead' when 100 then 'Case Initiated' when 1000 then 'File Closed' else L_CaseStages_Start.CaseStage_Title end as StageStart,")
                .Append("CASE EventLink_StageEnd when 0 then 'After Closed' when 999 then 'File Closed' else L_CaseStages_Start.CaseStage_Title end as StageEnd ")
                .Append("FROM I_EventLinks INNER JOIN L_EventTypes ON I_EventLinks.EventLink_EventTypeID = L_EventTypes.EventType_ID LEFT OUTER JOIN Sec_Access ON I_EventLinks.EventLink_SecAccess = Sec_Access.SecAccess_ID")
                .Append(" LEFT OUTER JOIN L_CaseStages L_CaseStages_Start ON I_EventLinks.EventLink_StageStart = L_CaseStages_Start.CaseStage_Number")
                .Append(" LEFT OUTER JOIN L_CaseStages L_CaseStages_End ON I_EventLinks.EventLink_StageEnd = L_CaseStages_End.CaseStage_Number")
                .Append(" WHERE I_EventLinks.EventLink_EventGroupID = " & EventGroupId & " ORDER By EventLink_Order")
            End With
            'Return dataAccess.GetSQLDataTable("CRM3_GetEventInGroupFromID " & EventGroupId)
            Return dataAccess.GetSQLDataTable(sql.ToString)
        Catch ex As Exception
            Return Nothing
        Finally
            dataAccess = Nothing
            sql = Nothing
        End Try

    End Function

    'Public Function AddEventType(ByVal EventTypeName As String, ByVal Scope As Integer, ByVal ClientType As Integer, ByVal EventLogMessage As String) As Integer

    '    Dim SQL As New StringBuilder
    '    Dim EventTypeId As Integer
    '    Dim Msg As String

    '    With SQL
    '        .Append("Insert Into L_EventTypes (EventType_Name, EventType_Scope, EventType_CustomerType)")
    '        .Append(" VALUES('" & SwapQuotes(EventTypeName.Trim) & "'," & Scope & ", " & ClientType & ")")
    '    End With

    '    If Not DB.ExecuteSQL(SQL.ToString) Then
    '        Exit Function
    '    End If

    '    EventTypeId = DB.GetIdentity


    '    Msg = "New Event Type Added: " & EventTypeId & " (" & EventTypeName & ")" & EventLogMessage

    '    GblFunc_Add_SysEvent("Admin (Event Types)", Msg)

    '    Return EventTypeId

    'End Function

    'Public Function ReorderEventLinks(ByVal EventGroupId As Integer, ByVal Order As Integer) As Boolean

    '    Dim SQL As New StringBuilder

    '    With SQL
    '        .Append("Update I_EventLinks Set EventLink_Order = EventLink_Order -1 ")
    '        .Append(" WHERE EventLink_EventGroupId = " & EventGroupId)
    '        .Append(" AND EventLink_Order > " & Order)
    '    End With

    '    Return DB.ExecuteSQL(SQL.ToString)

    'End Function

    'Public Function GetEventLink(ByVal EventTypeId As Integer) As DataTable  'EventLinkInfo

    '    Dim SQL As New StringBuilder
    '    'Dim myEventLink As New EventLinkInfo
    '    Dim myTable As New DataTable

    '    With SQL
    '        .Append("select eventlink_id,eventlink_eventtypeid,eventlink_eventgroupid,eventlink_order,eventlink_stagestart,eventlink_stageend ")
    '        .Append("from I_EventLinks Where EventLink_EventTypeID = " & EventTypeId)
    '    End With

    '    myTable = DB.GetSQLDataTable(SQL.ToString)

    '    'If Not IsNothing(myTable) Then
    '    '    If myTable.Rows.Count > 0 Then
    '    '        Dim myRow As DataRow = myTable.Rows(0)

    '    '        With myEventLink
    '    '            .EventLinkId = myRow.Item("eventlink_id")
    '    '            .EventLinkTypeId = myRow.Item("eventlink_eventtypeid")
    '    '            .EventGroupId = myRow.Item("eventlink_eventgroupid")
    '    '            .EventLinkOrder = myRow.Item("eventlink_order")
    '    '            .EventLinkStageStart = myRow.Item("eventlink_stagestart")
    '    '            .EventLinkStageEnd = myRow.Item("eventlink_stagend")
    '    '        End With
    '    '    End If
    '    'End If

    '    'myTable.Dispose()

    '    Return myTable

    'End Function

    'Public Function DeleteEventLinks(ByVal EventTypeId As Integer)
    '    Return DB.ExecuteSQL("Delete from I_EventLinks Where EventLink_EventTypeID = " & EventTypeId)
    'End Function

    'Public Function DeleteEventType(ByVal EventTypeId As Integer) As Boolean
    '    Return DB.ExecuteSQL("Delete from L_EventTypes where EventType_ID = " & EventTypeId)
    'End Function

    Public Function GetEvent(ByVal EventId As Long) As EventInfo



        ' Dim SQL As New StringBuilder
        Dim dataAccess As New Global_Visas_Data_Layer.DataAccess
        Dim myEventInfo As New EventInfo
        Dim myData As DataTable
        Try
            'With SQL
            '    .Append("SELECT D_Event.Event_Category, D_Event.Event_Description, D_Event.Event_Message, D_Event.Event_DTEntered, D_Event.Event_DTScheduled, ")
            '    .Append(" D_Event.Event_DTCompleted, D_Event.Event_LinkType, D_Event.Event_LinkID, D_Event.Event_VIP, D_Event.Event_KeyDate,")
            '    .Append(" L_Consultant.con_name AS EnteredBy, L_Consultant_Sch.con_name AS SchedFor, L_Consultant_Comp.con_name AS CompBy")
            '    .Append(" FROM L_Consultant RIGHT OUTER JOIN")
            '    .Append(" L_Consultant L_Consultant_Sch RIGHT OUTER JOIN")
            '    .Append(" D_Event LEFT OUTER JOIN")
            '    .Append(" L_Consultant L_Consultant_Comp ON D_Event.Event_CompletedBy = L_Consultant_Comp.Con_ID ON")
            '    .Append(" L_Consultant_Sch.Con_ID = D_Event.Event_ScheduledFor ON L_Consultant.Con_ID = D_Event.Event_Enteredby")
            '    .Append(" WHERE (D_Event.Event_ID = " & EventId & ")")
            myData = dataAccess.GetSQLDataTable("CRM3_GetEventInfoFromID " & EventId)
            ' End With

            If Not IsNothing(myData) Then
                If myData.Rows.Count > 0 Then
                    Dim myRow As DataRow = myData.Rows(0)

                    With myEventInfo
                        .EventId = EventId
                        .CategoryId = myRow.Item("event_category")
                        .CompletedBy = IIf(IsDBNull(myRow.Item("compby")), "", myRow.Item("compby"))
                        .DateCompleted = IIf(IsDBNull(myRow.Item("event_dtcompleted")), Nothing, myRow.Item("event_dtcompleted"))
                        .DateEntered = IIf(IsDBNull(myRow.Item("event_dtentered")), Nothing, myRow.Item("event_dtentered"))
                        .DateScheduled = IIf(IsDBNull(myRow.Item("event_dtscheduled")), Nothing, myRow.Item("event_dtscheduled"))
                        .Description = IIf(IsDBNull(myRow.Item("event_description")), "", myRow.Item("event_description"))
                        .EnteredBy = IIf(IsDBNull(myRow.Item("enteredby")), "", myRow.Item("enteredby"))
                        .KeyDate = myRow.Item("event_keydate")
                        .LinkId = myRow.Item("event_linkid")
                        .LinkType = myRow.Item("event_linktype")
                        .Message = IIf(IsDBNull(myRow.Item("event_message")), "", myRow.Item("event_message"))
                        .ScheduledFor = IIf(IsDBNull(myRow.Item("schedfor")), "", myRow.Item("schedfor"))
                        .VIP = myRow.Item("event_vip")
                    End With
                End If
            End If
            Return myEventInfo
        Catch ex As Exception
            Return Nothing
        Finally
            dataAccess = Nothing
        End Try
    End Function


    Public Function GblFunc_Add_SysEvent(ByVal EventType As String, ByVal Detail As String) As Boolean

        ' Dim SQL As New StringBuilder
        Dim dataAccess As New Global_Visas_Data_Layer.DataAccess
        Dim cmn As New Global_Visas_Business_Layer.CommonFuncs
        Try
            'dataAccess.GetSQLScalar("CRM3_AddSystemEvent " & "0," & GlobalCRM.CurrentConID & ",'" & cmn.SwapQuotes(GlobalCRM.CurrentConName) & "','" & cmn.SwapQuotes(EventType) & "','" & cmn.SwapQuotes(Detail) & "'," & "1")
            Dim SQL As New StringBuilder
            Dim assembly As System.Reflection.Assembly = System.Reflection.Assembly.GetExecutingAssembly

            Dim sversion As Version = assembly.GetName().Version


            With SQL

                .Append("Insert into S_SysEvents (SysEvent_UserID, SysEvent_Username, SysEvent_Type, SysEvent_Detail, SysEvent_SysVersion)")
                .Append(" Values ( ")
                .Append(GlobalCRM.CurrentConID & ", ")
                .Append("'" & cmn.SwapQuotes(GlobalCRM.CurrentConName) & "',")
                .Append("'" & cmn.SwapQuotes(EventType) & "',")
                .Append(" '" & cmn.SwapQuotes(Detail) & "',")
                '.Append ( " 'V1:" & Gbl_Int_SysVersion & Gbl_Str_SubVersion & "')"
                .Append("'V" & sversion.ToString & "')")
            End With

            Return dataAccess.ExecuteSQL(SQL.ToString)
        Catch ex As Exception
            Return False
        Finally
            dataAccess = Nothing
            cmn = Nothing
        End Try
        'With SQL

        '    .Append("Insert into S_SysEvents (SysEvent_UserID, SysEvent_Username, SysEvent_Type, SysEvent_Detail, SysEvent_SysVersion)")
        '    .Append(" Values ( ")
        '    .Append(GlobalCRM.CurrentConID & ", ")
        '    .Append("'" & SwapQuotes(GlobalCRM.CurrentConName) & "',")
        '    .Append("'" & SwapQuotes(EventType) & "',")
        '    .Append(" '" & SwapQuotes(Detail) & "',")
        '    '.Append ( " 'V1:" & Gbl_Int_SysVersion & Gbl_Str_SubVersion & "')"
        '    .Append("'V" & ApplicationIdentityProductVersion & "')")
        'End With

        'Return DB.ExecuteSQL(SQL.ToString)

    End Function
    Public Function DismissEvent(ByVal EventId As Long, ByVal ConId As Integer, ByVal CompletionNote As String, ByRef LinkId As Long, ByRef LinkType As TasksEvents.EventTypes) As Boolean
        Dim db As New Global_Visas_Data_Layer.DataAccess
        Dim cmn As New CommonFuncs
        Dim SQL As StringBuilder

        Dim myData As DataTable
        Try
            SQL = New StringBuilder
            SQL.Append("Select Event_message, Event_LinkId, Event_LinkType from D_Event where Event_ID = " & EventId)

            myData = db.GetSQLDataTable(SQL.ToString)

            If Not IsNothing(myData) Then
                If myData.Rows.Count > 0 Then

                    Dim myRow As DataRow = myData.Rows(0)
                    Dim Msg As String = myRow.Item("event_message") & vbCrLf & "---------------------------------------------------------" & vbCrLf & "Completion message" & vbCrLf & vbCrLf & CompletionNote.Trim

                    LinkId = myRow.Item("Event_LinkID")
                    LinkType = myRow.Item("Event_Linktype")

                    SQL = New StringBuilder

                    With SQL
                        .Append("UPDATE D_Event ")

                        .Append(" SET Event_Category = 3")
                        .Append(", Event_CompletedBy = '" & ConId & "'")
                        .Append(", Event_DTCompleted = '" & cmn.FormatDate(Now, True) & "'")
                        .Append(", Event_message = '" & cmn.SwapQuotes(Msg) & "'")
                        .Append(" WHERE Event_ID = " & EventId)
                    End With

                    Return db.ExecuteSQL(SQL.ToString)

                End If
            End If

        Catch ex As Exception
        Finally
            db = Nothing
            SQL = Nothing
            myData = Nothing
            cmn = Nothing
        End Try
    End Function
    Public Shared Function GetWebCommentsEvent(ByVal CaseID As Long) As String
        ' get the event that contains the user comments submitted via web site
        Dim db As New Global_Visas_Data_Layer.DataAccess
        Dim SQL As StringBuilder
        Dim Msg As StringBuilder
        Dim myTab As DataTable
        Try
            SQL = New StringBuilder
            With SQL
                .Append("Select Event_Description, Event_Message, Event_DTEntered ")
                .Append(" From D_Event ")
                .Append(" Where Event_LinkType = 1 ")
                .Append(" AND Event_LinkID = " & CaseID)
                .Append(" AND Event_Description = 'Website Comments'")
                .Append(" ORDER BY Event_ID")
            End With

            myTab = db.GetSQLDataTable(SQL.ToString)
            Msg = New StringBuilder
            If Not IsNothing(myTab) Then
                If myTab.Rows.Count > 0 Then
                    Dim myRow As DataRow
                    myRow = myTab.Rows(0)
                    Msg.Append(myRow("Event_Message"))
                Else
                    Msg.Append("No Comments Found")
                End If
            Else
                Msg.Append("No Comments Found")
            End If

            Return Msg.ToString
        Catch ex As Exception
            Return String.Empty
        Finally
            db = Nothing
            SQL = Nothing
            myTab = Nothing
            Msg = Nothing
        End Try
    End Function

    Public Function DeleteEvent(ByVal EventId As Long, ByVal EventMessage As String) As Boolean
        Dim DB As New Global_Visas_Data_Layer.DataAccess
        If DB.ExecuteSQL("Delete from D_Event where Event_ID = " & EventId) Then
            GblFunc_Add_SysEvent("Admin (Event)", EventMessage)
            Return True
        End If

    End Function

    Public Function EditEvent(ByVal EventId As Long, ByVal Description As String, ByVal EventText As String, ByVal EventLogMessage As String) As Boolean

        Dim SQL As New StringBuilder
        Dim DB As New Global_Visas_Data_Layer.DataAccess
        With SQL
            .Append("Update D_Event set ")
            .Append(" Event_Description = '" & (New CommonFuncs).SwapQuotes(Description) & "', ")
            .Append(" Event_Message = '" & (New CommonFuncs).SwapQuotes(EventText) & "'")
            .Append(" Where Event_ID = " & EventId)
        End With

        If Not DB.ExecuteSQL(SQL.ToString) Then
            GblFunc_Add_SysEvent("Admin (Event)", EventLogMessage)
            Return True
        End If

    End Function
End Class
